<html>
<head><meta charset="utf-8"><title>generic parameter ordering · project-const-generics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/index.html">project-const-generics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html">generic parameter ordering</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221477589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221477589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221477589">(Jan 03 2021 at 23:42)</a>:</h4>
<p>I want to revisit this question, because it's relevant especially for const generic defaults, which would be good to stabilise before full const generics. I think the most sensible thing is to drop the order entirely, except for the requirement that all defaulted parameters come after non-defaulted parameters (which is a necessary restriction to tell which argument corresponds to which parameter).</p>



<a name="221477608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221477608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221477608">(Jan 03 2021 at 23:43)</a>:</h4>
<p>I don't think there's any technical reason lifetimes were previously constrained to come after type parameters, but it made sense because lifetimes don't depend on types. However, if we allow consts and types to be interleaved (which is necessary, because defaulted type parameters must follow const parameters), it feels strange to keep lifetime parameters constrained.</p>



<a name="221477708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221477708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221477708">(Jan 03 2021 at 23:46)</a>:</h4>
<p>To clarify, I think the simplest design is: non-defaulted parameters, followed by defaulted parameters, such that each parameter can only refer to parameters that precede it.</p>



<a name="221477757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221477757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221477757">(Jan 03 2021 at 23:46)</a>:</h4>
<p>For some reason I remember that generic parameters could refer to following generic parameters, but when I try to come up with an example, I get <code>type parameters with a default cannot use forward declared identifiers</code>, so maybe I'm misremembering.</p>



<a name="221477793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221477793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221477793">(Jan 03 2021 at 23:47)</a>:</h4>
<p>I think the best approach might be to write an RFC for <code>const_generics_defaults</code> which includes relaxing the parameter ordering constraints.</p>



<a name="221478015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221478015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221478015">(Jan 03 2021 at 23:53)</a>:</h4>
<p><span class="user-mention" data-user-id="121053">@varkor</span> I think lifetimes can reference following type parameters</p>



<a name="221478019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221478019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221478019">(Jan 03 2021 at 23:53)</a>:</h4>
<p>Like <code>fn f&lt;'a: 'b, 'b&gt;() {}</code></p>



<a name="221478081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221478081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221478081">(Jan 03 2021 at 23:55)</a>:</h4>
<p>Ah, thanks, that's the sort of thing I was thinking of.</p>



<a name="221478125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221478125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221478125">(Jan 03 2021 at 23:56)</a>:</h4>
<p>I think it'd be good to change that, but I doubt it's viable to do so now.</p>



<a name="221478374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221478374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221478374">(Jan 04 2021 at 00:02)</a>:</h4>
<p>I have definitely used this in my own code <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="221478476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221478476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221478476">(Jan 04 2021 at 00:04)</a>:</h4>
<p>Yeah, I think lifetimes should continue to be exempt from the ordering rule.</p>



<a name="221498519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221498519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> dubi steinkek <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221498519">(Jan 04 2021 at 08:20)</a>:</h4>
<p>Is</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Type</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">PRED</span>: <span class="nc">fn</span><span class="p">(</span><span class="n">T</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">bool</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>something that needs to be considered as a future possibility?</p>



<a name="221502832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221502832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221502832">(Jan 04 2021 at 09:18)</a>:</h4>
<p><span class="user-mention silent" data-user-id="233194">dubi steinkek</span> <a href="#narrow/stream/260443-project-const-generics/topic/generic.20parameter.20ordering/near/221498519">said</a>:</p>
<blockquote>
<p>Is</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Type</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">PRED</span>: <span class="nc">fn</span><span class="p">(</span><span class="n">T</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">bool</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>something that needs to be considered as a future possibility?</p>
</blockquote>
<p>maybe <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> i am slowly getting a bit more hopeful about this though this will still take a long while if ever</p>
<p>we should at least try to not prevent ourselves from allowing this in the future</p>



<a name="221514473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/generic%20parameter%20ordering/near/221514473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/generic.20parameter.20ordering.html#221514473">(Jan 04 2021 at 11:46)</a>:</h4>
<p><span class="user-mention silent" data-user-id="233194">dubi steinkek</span> <a href="#narrow/stream/260443-project-const-generics/topic/generic.20parameter.20ordering/near/221498519">said</a>:</p>
<blockquote>
<p>Is</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Type</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">PRED</span>: <span class="nc">fn</span><span class="p">(</span><span class="n">T</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">bool</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>something that needs to be considered as a future possibility?</p>
</blockquote>
<p>I would love to see this at some point in the future, though it's won't be supported any time soon. This doesn't pose any problem for the ordering restriction I suggested, though.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>